package com.yunhe.java.Day11.Demo;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
/**
 * Created by Administrator on 2017/8/4 0004.
 */
public class Teacher {
    private String name;
    private Integer id;
    private static List courselist;
    private static Scanner sc;
    static {
        courselist=new ArrayList();
        sc=new Scanner(System.in);
    }
    public Teacher(){
    }
    //添加课程
    public void AddCourse(){
        System.out.println("**************************请开始录入课程*****************************");
        while(true){
            System.out.print("请输入课程id:"+" ");
            Integer id=sc.nextInt();
            System.out.print("请输入课程全称:"+" ");
            String name= sc.next();
            courselist.add(new Course(id,name)) ;
            System.out.println("是否继续添加课程y/n");
            String fla=sc.next();
            if(fla.equals("n")){
                break;
            }
        }
        showList();
    }
    //显示课程列表
     public void showList(){
         System.out.println("**************************以下是课程列表******************************");
         for(Object obj:courselist){
             Course course = (Course)obj;//关键
             System.out.print(course.getId()+"."+course.getName()+" ");
         }
         System.out.println("1.添加课程 2.删除课程 3.修改课程");
         System.out.print("请输入数字");
         int i = sc.nextInt();
         switch (i) {
             case 1 : AddCourse();break;
             case 2 : DelCourse();break;
             case 3 : UpdateCourse();break;
             default: showList();
         }
     }
     //删除课程
     public void DelCourse(){
         System.out.println("******************************课程删除*********************************");
         System.out.println("请输入要删除的课程编号");
         Integer i= sc.nextInt();
         courselist.remove(i-1);
         System.out.println("课程已删除");
         showList();
     }
     //修改课程
    public void UpdateCourse(){
        System.out.println("******************************课程更改*******************************");
        System.out.println("请输入要修改的课程编号");
        Integer i= sc.nextInt();
        courselist.set(i-1,new Course(i,name ));
        System.out.println("课程已删除");
        showList();
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public static List getCourselist() {
        return courselist;
    }

    public static void setCourselist(List courlist) {
        Teacher.courselist = courlist;
    }

    public static Scanner getSc() {
        return sc;
    }

    public static void setSc(Scanner sc) {
        Teacher.sc = sc;
    }
}
